<!DOCTYPE html>
<html>

<head>
    <title>编辑游记</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <link href="/js/plugins/chosen/chosen.css" type="text/css" rel="stylesheet" />

    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/editTravels.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css" />
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/plugins/My97DatePicker/WdatePicker.js"></script>
    <script src="/js/plugins/eleditor/Eleditor.min.js"></script>
    <script src="/js/plugins/eleditor/webuploader.min.js"></script>
    <script src="../js/common.js"></script>

    <script type="text/javascript" src="/js/plugins/chosen/chosen.jquery.js"></script>
    <!--时间控件-->
    <!--<link href="/css/mobiscroll/mobiscroll.frame.css" rel="stylesheet" type="text/css"/>
    <link href="/css/mobiscroll/mobiscroll.frame.android-holo.css" rel="stylesheet" type="text/css"/>
    <link href="/css/mobiscroll/mobiscroll.scroller.css" rel="stylesheet" type="text/css"/>
    <link href="/css/mobiscroll/mobiscroll.android-holo-light.css" rel="stylesheet" type="text/css"/>
    <script src="/js/plugins/mobiscroll/zepto.min.js"></script>
    <script src="/js/plugins/mobiscroll/mobiscroll.zepto.js"></script>
    <script src="/js/plugins/mobiscroll/mobiscroll.core.js"></script>
    <script src="/js/plugins/mobiscroll/mobiscroll.frame.js"></script>
    <script src="/js/plugins/mobiscroll/mobiscroll.scroller.js"></script>
    <script src="/js/plugins/mobiscroll/mobiscroll.util.datetime.js"></script>
    <script src="/js/plugins/mobiscroll/mobiscroll.datetimebase.js"></script>
    <script src="/js/plugins/mobiscroll/mobiscroll.datetime.js"></script>
    <script src="/js/plugins/mobiscroll/mobiscroll.android-holo-light.js"></script>
    <script src="/js/plugins/mobiscroll/i18n/mobiscroll.i18n.zh.js"></script>-->
    <!--$(function () {
    $('#pickTime').mobiscroll().date({
    theme: "android-holo-light",
    mode: "scroller",
    display: "bottom",
    lang: "zh"
    });
    });-->


    <script>
        $(function () {
            $("#changeBtn").click(function () {
                $("#imageInput").click();
            })
            //值改变事件
            $("#imageInput").change(function () {
                $("#imageForm").ajaxSubmit(function (data) {
                    console.log(data);
                    if(data.status==1){
                        $("#coverUrl").attr("src",data.url)
                    }
                })
            })

            //回显地区
            var html="";
            $.get("/regions",function (data) {
                console.log(data);
                $.each(data,function (index, ele) {
                    html+="<option value='"+ele.id+"'>"+ele.name+"</option>"
                })
                $("select[name='place.id']").html(html);



                //由于都是异步请求,所以时间先后存在差异,直接将其放在地区回显的内部
                //获取传递过来的id
                var params=getParams();
                console.log(params);
                if(params.id){

                    $.get("/travels",params,function (data) {
                        console.log(data);
                        $(".travels").renderValues(data);
                    })
                    //设置id值
                    $("input[name=id]").val(params.id);
                    $("input[name='_method']").val("put");
                }
            })


            var Edr = new Eleditor({
                el: '#contentEditor',
                upload:{
                    server: "/images",//后台接收地址
                    formName: 'multipartFile'//form表单提交后后台接收文件的名字
                }
            });



            /*
            * 	提供在执行表单提交之前，处理数据的回调函数。
                签名：function(a,form,options)
                函数说明：通过formToArray(options.semantic, elements)返回的表单元素数组、当前表单对象、options参数集合
                返回值：返回false，表示终止表单提交操作。*/
            //jQueryForm获取额外参数

            $("#save").click(function () {
                $("#detailForm").ajaxSubmit({
                    beforeSubmit:function (arr,form,options) {
                        arr.push({name:"title",value:$("#title").val()})
                        arr.push({name:"coverUrl",value:$("#coverUrl").attr("src")})
                        arr.push({name:"state",value:$("#save").data("state")})
                        //内容
                        arr.push({name:"travelContent.content",value:Edr.getContent()})
                    },
                    success:function (data) {
                        if(data.success){
                            window.location.href="/mine/travels.html";
                        }else{
                            $(document).dialog({
                                autoClose: 2500,
                                content: data.msg
                            });
                        }
                    }
                })
            })
            $("select[name='place.id']").chosen();

        })
    </script>



</head>



<body>

<form action="/images" method="post" id="imageForm" enctype="multipart/form-data">
    <input type="file" name="multipartFile" id="imageInput" style="display: none;"/>
</form>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:window.history.go(-1);">
                <span><i class="fa fa-times"></i></span>
            </a>
        </div>
        <div class="col-5"></div>
        <div class="col" style="text-align: right;">
            <i class="fa fa-floppy-o fg-fw" id="save" data-state="1"><span>保存</span></i>
            <i class="fa fa-check" id="release" data-state="3"><span>发布</span></i>
        </div>
    </div>
</div>

<div class="travels form-group">
    <div class="cover">
        <img id="coverUrl" width="100%" height="200px" render-src="coverUrl" />
        <form id="coverForm" method="post" enctype="multipart/form-data">
            <input type="file" name="pic" style="display: none" accept="image/gif,image/jpeg,image/jpg,image/png"/>
            <button type="button" class="btn" id="changeBtn">
                <i class="fa fa-pencil-square-o"></i>
                <small>更换封面</small>
            </button>
        </form>

    </div>
    <div class="title">
        <input class="form-control" id="title"  placeholder="请输入标题" render-value="title"/>
    </div>
    <h6 href="#">编辑</h6>
    <div id="contentEditor" render-html="travelContent.content">

    </div>
    <hr/>
    <div class="container">
        <form id="detailForm" method="post" action="/travels">
            <input type="hidden" name="id" />
            <input type="hidden" name="_method"/>
            <label>出行时间:</label>
            <!--使用My97DatePicker input输入框的末尾添加onclick="WdatePicker()"-->
            <input type="text" name="travelTime" id="pickTime" class="form-control" onclick="WdatePicker()" render-value="travelTime">
            <label>出行天数:</label>
            <input type="number" name="days" class="form-control" render-value="days">
            <label>参与人物:</label>
            <select class="c-select form-control" name="person" render-value="person" >
                <option value="1" selected>一个人的旅行</option>
                <option value="2">和父母</option>
                <option value="3">和朋友</option>
                <option value="4">和同事</option>
                <option value="5">和爱人</option>
                <option value="6">和其他</option>
            </select>
            <label>人均费用:</label>
            <input type="text" name="perExpends" class="form-control" render-value="perExpends">

            <label>旅游地点:</label>
            <select class="form-control" name="place.id" render-value="place.id">

            </select>


            <div class="form-check">
                <label class="form-check-label">
                    <input class="form-check-input" type="checkbox"  name="isPublic" render-attr="checked=isPublic">是否公开
                </label>
            </div>

        </form>
    </div>

    <hr/>

</div>


</body>

</html>